<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%> 

  		<div class="" style="padding: 5px;"> 
				<button id="id-btn-dialog1" class="btn btn-sm btn-primary">增加字典</button> 
				<button id="id-btn-dialog3" class="btn btn-sm btn-primary">删除字典</button> 
			</div>
			<table class="table table-striped table-hover table-bordered">
					  <thead>
						<tr id="sys_dict_table_title">
						  <th  width="60">编号</th>
						  <th  width="40" fname="dictNameCheckBox"><input id="dictNameCheckBox" type="checkbox"></th>
						  <th  width="60" fname="dictName">名称</th> 
						  <th  width="60" fname="dictSign">标识</th>
						  <th  width="60" fname="value1">值1</th>
						  <th  width="40" fname="value2">值2</th>
						  <th  width="40" fname="value3">值3</th>
						  
						  <th  width="100" fname="showTime">创建时间</th> 
						</tr>
					  </thead>
					  <tbody id="sys_dict_table">
						 
					  </tbody>
					</table> 
					<ul class="pagination" id="dict_pagination">
					  
					</ul> 		
<script type="text/javascript">
	(function() { 
		
		
			//改变他的启用禁用的状态
			function changedictState(){
				var allstate =$("div[name='sys_dict_table_state_tr_td']");
				for(var i=0;i<allstate.length;i++){
					var bc = $(allstate[i]);
					if(bc.text()==1){
						bc.html('<font color="green">启用</font>');
					}else if(bc.text()==0){
						bc.html('<font color="red">禁用</font>');
					}
				}
				$("#sys_dict_table").children().click(function(){
					if($(this).find("[name=sys_dict_table_checkbox]")[0].checked==true){
						$(this).find("[name=sys_dict_table_checkbox]")[0].checked=false;
					}else{
						$(this).find("[name=sys_dict_table_checkbox]")[0].checked=true;
					}
				});
			};
			 
			//全选中事件
			$("#dictNameCheckBox").click(function(){
				var allc =$("[name=sys_dict_table_checkbox]");
				for(var i=0;i<allc.length;i++){
					$(allc[i])[0].checked=$(this)[0].checked;
				}
					 
			});
			//字典搜索
			function loaddict(event,data){
				if(typeof(data)=="undefined"){
					data={};
				}
				var url ="${pageContext.request.contextPath}/edu/dictAction.do?method=getDict";
				data.dictName=$("#serch_text").val();
				data.tell=$("#serch_text").val();
				data.dictShowName=$("#serch_text").val();
				data.dictEngListName=$("#serch_text").val();
				var cp =$("#dict_pagination").find(".active");
				data.start=1;
				if(cp.length>0){
					var ccp=$(cp[0]).text();
					if(parseInt(ccp)){
						data.start=ccp;
					}
				}  
				$("#table_dict").wgrid({
							table_title:"sys_dict_table_title",
							tbodyId:"sys_dict_table",
							pagination:"dict_pagination",
							url:url,
							checkbox:true,
							data:data,
							success:function(){
								changedictState();
								 
							}
				});
			};
		 //显示增加页面
		 function showdictAdd(){
		 
			    $("#user_include").html("");
			 	$("#user_include").load("${pageContext.request.contextPath}/dictAdd.jsp?r="+Math.random(),{},function(){
			 		var dialog = $("#dialog-message").removeClass('hide').dialog({
						modal: true,
						title: "增加字典",
						width:800,
						close:function(){
							$(this).dialog('destroy'); 
							$("#user_include").html("");
							loaddict(null,{});
						},
						title_html: true,
						buttons: [  
							{
								text: "提交",
								"class" : "btn btn-primary btn-xs",
								click: function() {
									window.dictAdd.adddict(this);
									
								} 
							}
						]
					}); 
				}); 
		 };
		//弹出字典增加页面
		$("#id-btn-dialog1" ).on('click', function(e) {
			e.preventDefault();
			showdictAdd();
		});
		 
		 
		//删除一个字典
		function dictDelete(){
			var allc =$("input[type=checkbox][name=sys_dict_table_checkbox]:checked");
			if(allc.length<=0){
				alert("你没有选中字典,不能进行删除操作!");
				return;
			}
			var arr = [];
			for(var i=0;i<allc.length;i++){
				arr.push($(allc[i]).parent().parent().attr("id"));
			}
			$.ajax({
				type: "POST",
				url:"${pageContext.request.contextPath}/edu/dictAction.do?method=deletedict",
				data:{allId:obj2str(arr)},
				dataType:'json',
				success: function(msg){
					alert(msg.message); 
					loaddict(null,{});
				}
			});	
			 
		};
		//启用和禁用一个字典
		function disDelete(temp){
			var allc =$("input[type=checkbox][name=sys_dict_table_checkbox]:checked");
			if(allc.length<=0){
				alert("你没有选中字典,不能进行启用和禁用操作!");
				return;
			}
			var arr = [];
			for(var i=0;i<allc.length;i++){
				arr.push($(allc[i]).parent().parent().attr("id"));
			}
			$.ajax({
				type: "POST",
				url: "${pageContext.request.contextPath}/edu/sysdictAction.do?method=disdict",
				data:{allId:obj2str(arr),flag:temp},
				dataType:'json',
				success: function(msg){
					alert(msg.message); 
					loaddict(null,{});
				}
			});	
		};
		//删除选中字典
		$("#id-btn-dialog3" ).on('click', function(e) {
			e.preventDefault();
			dictDelete();
		});
		$(function(){
			loaddict(null,{});
		}); 
		window.dict={};
		window.dict.loaddict=loaddict;
		window.dict.disDelete=disDelete;
	})();
</script>

